package test.order.controller;


import com.github.pagehelper.PageInfo;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import test.order.pojo.Reporttable;
import test.order.service.ReporttableService;

import java.util.List;

/****
 * @Author:shenkunlin
 * @Description:
 * @Date 2019/6/14 0:18
 *****/

@RestController
@RequestMapping("/reporttable")
@CrossOrigin
public class ReporttableController {

    @Autowired
    private ReporttableService reporttableService;

    /***
     * Reporttable分页条件搜索实现
     * @param reporttable
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false) Reporttable reporttable, @PathVariable  int page, @PathVariable  int size){
        //调用ReporttableService实现分页条件查询Reporttable
        PageInfo<Reporttable> pageInfo = reporttableService.findPage(reporttable, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * Reporttable分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用ReporttableService实现分页查询Reporttable
        PageInfo<Reporttable> pageInfo = reporttableService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param reporttable
     * @return
     */
    @PostMapping(value = "/search" )
    public Result<List<Reporttable>> findList(@RequestBody(required = false)  Reporttable reporttable){
        //调用ReporttableService实现条件查询Reporttable
        List<Reporttable> list = reporttableService.findList(reporttable);
        return new Result<List<Reporttable>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Integer id){
        //调用ReporttableService实现根据主键删除
        reporttableService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改Reporttable数据
     * @param reporttable
     * @param id
     * @return
     */
    @PutMapping(value="/{id}")
    public Result update(@RequestBody  Reporttable reporttable,@PathVariable Integer id){
        //设置主键值
        reporttable.setId(id);
        //调用ReporttableService实现修改Reporttable
        reporttableService.update(reporttable);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增Reporttable数据
     * @param reporttable
     * @return
     */
    @PostMapping
    public Result add(@RequestBody   Reporttable reporttable){
        //调用ReporttableService实现添加Reporttable
        reporttableService.add(reporttable);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询Reporttable数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<Reporttable> findById(@PathVariable Integer id){
        //调用ReporttableService实现根据主键查询Reporttable
        Reporttable reporttable = reporttableService.findById(id);
        return new Result<Reporttable>(true,StatusCode.OK,"查询成功",reporttable);
    }

    /***
     * 查询Reporttable全部数据
     * @return
     */
    @GetMapping
    public Result<List<Reporttable>> findAll(){
        //调用ReporttableService实现查询所有Reporttable
        List<Reporttable> list = reporttableService.findAll();
        return new Result<List<Reporttable>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
